package com.fei.user.service;

import com.fei.user.mapper.UserMapper;
import com.fei.user.pojo.User;
import com.fei.user.pojo.UserDTO;
import com.fei.user.utils.CodecUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    /**
     * @return
     */
    public User queryUser(UserDTO user2) {

        //查询
        User record = new User();
        record.setUsername(user2.getUsername());
        User user = this.userMapper.selectOne(record);
        //若明湖为null
        if (user == null) {
            return null;
        }
        //校验用户名
        if (!user.getPassword().equals(user2.getPassword())) {
            return null;
        }
        //用户名密码都正确
        return user;
    }

    public Boolean checkData(String data, Integer type) {
        User record = new User();
        switch (type) {
            case 1:
                record.setUsername(data);
                break;
            case 2:
                record.setPhone(data);
                break;
            default:
                return null;
        }
        return this.userMapper.selectCount(record) == 0;
    }
}
